﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SAServices.Model;

namespace SAServices.DAL
{
    internal class LoginDAL
    {
        internal static List<String> GetRoleByUserNm(Model.ConnectionConext connCtx, string userNm)
        {
            string sql = String.Format("SELECT R.[RoleName] AS RoleName FROM [aspnet_Roles] R, [aspnet_UsersInRoles] UR,[aspnet_Users] U WHERE U.[UserName] = '{0}' "+
            "AND U.[UserId]=UR.[UserId] AND UR.[RoleId]=R.[RoleId];", userNm);

            DataTable dt = GenDAL.GetTable(connCtx, sql);

            List<String> retList = new List<String>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string ret = Convert.ToString(dt.Rows[i]["RoleName"]);
                //Guid tempId = new Guid(ret);

                retList.Add(ret);
            }

            return retList;
        }


        //internal static bool ValidateUser(Model.ConnectionConext connCtx, string username,string password)
        //{
        //    string sql = String.Format("SELECT R.[RoleName] AS RoleName FROM [aspnet_Roles] R, [aspnet_UsersInRoles] UR,[aspnet_Users] U WHERE U.[UserName] = '{0}' " +
        //    "AND U.[UserId]=UR.[UserId] AND UR.[RoleId]=R.[RoleId];", userNm);

        //    DataTable dt = GenDAL.GetTable(connCtx, sql);

        //    List<String> retList = new List<String>();

        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        string ret = Convert.ToString(dt.Rows[i]["RoleName"]);
        //        //Guid tempId = new Guid(ret);

        //        retList.Add(ret);
        //    }

        //    return retList;
        //}

    }
}
